use std::net::TcpListener;
use std::net::TcpStream;
use std::{
    io::{prelude::*, ErrorKind},
    thread,
};

struct Proxy {
    listener: TcpListener,
}

impl Proxy {
    pub fn new(listen_host: &str) -> Self {
        let listener = TcpListener::bind(listen_host).unwrap();
        Proxy { listener }
    }
    pub fn run(&self) {
        // 有请求过来就新开一个线程来处理
        for client in self.listener.incoming() {
            let client = client.unwrap();
            thread::spawn(move || {
                handle_connection(client);
            });
        }
    }
}
